package com.blb.community.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.community.Annotation.Log;
import com.blb.community.entity.SysUser;
import com.blb.community.entity.ZyOwnerRoom;
import com.blb.community.entity.ZyOwnerRoomRecord;
import com.blb.community.entity.vo.ZyOwnerRoomVO;
import com.blb.community.service.ISysUserService;
import com.blb.community.service.IZyOwnerRoomRecordService;
import com.blb.community.service.IZyOwnerRoomService;
import com.blb.community.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 帅帅
 * @Date 2022/7/14 20:38
 * @PackageName:com.blb.community.controller
 * @ClassName: AuditController
 * @Description: 业主审核
 * @Version 1.0
 */
@Api(tags = "查询审核信息")
@RestController
@RequestMapping("/audit")
public class AuditController {
    @Autowired
    private IZyOwnerRoomService zyOwnerRoomService;
    @Autowired
    private IZyOwnerRoomRecordService zyOwnerRoomRecordService;
    @Autowired
    private ISysUserService sysUserService;

    @ApiOperation("审核模糊查询")
    @PostMapping
    public ResponseResult<IPage<List<ZyOwnerRoomVO>>> getZyOwnerRoomList(@RequestBody ZyOwnerRoomVO zyOwnerRoomVO) {
        IPage<List<ZyOwnerRoomVO>> page = zyOwnerRoomService.getZyOwnerRoomList(zyOwnerRoomVO);
        return ResponseResult.ok(page);
    }

    @Log(module = "审核成功添加审核记录", operationType = 1, requestMethod = "POST")
    @ApiOperation("审核成功添加审核记录")
    @PostMapping("/auditingOk")
    public ResponseResult<String> auditingOk(@RequestBody ZyOwnerRoomRecord zyOwnerRoomRecord) {
        SysUser one = sysUserService.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, SecurityContextHolder.getContext().getAuthentication().getName()));
        zyOwnerRoomRecord.setCreateById(one.getUserId().toString());
        ZyOwnerRoom zyOwnerRoom = new ZyOwnerRoom();
        zyOwnerRoom.setOwnerRoomId(zyOwnerRoomRecord.getOwnerRoomId());
        zyOwnerRoom.setRoomStatus(zyOwnerRoomRecord.getRoomStatus());
        zyOwnerRoomRecordService.save(zyOwnerRoomRecord);
        zyOwnerRoomService.updateById(zyOwnerRoom);
        return ResponseResult.ok("添加成功");
    }

    @ApiOperation("查询绑定信息")
    @GetMapping("/{id}")
    public ResponseResult<List<ZyOwnerRoomRecord>> getZyOwnerRoomRecordInfo(@PathVariable String id) {
        List<ZyOwnerRoomRecord> list = zyOwnerRoomRecordService.getZyOwnerRoomRecordInfo(id);
        return ResponseResult.ok(list);
    }

}
